﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using MenuLib;

namespace Test2
{
    class Program
    {
        static Menu menu;
        static Menu deserMenu;
        static void Main(string[] args)
        {
            // menu = new Menu();

            // menu.Run();

            // Test1();

            /*
            FileStream fs = new FileStream("Menu.bin", FileMode.Create);
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fs, menu);
            fs.Close();

            fs = new FileStream("Menu.bin", FileMode.Open);
            deserMenu = (Menu)formatter.Deserialize(fs);
             */

            // menu.Save("Menu.bin");

            // deserMenu = Menu.Load("Menu.bin");

            // deserMenu.Run();

            menu = Menu.Load("UserMenu.bin");
            menu.Items["Create"].Select += new EventHandler(Program_Select);
            menu.Items["Remove"].Select += new EventHandler(Program_Select);
            menu.Items["Update"].Select += new EventHandler(Program_Select);
            menu.Run();
        }

        static void Program_Select(object sender, EventArgs e)
        {
            (sender as MenuItem).Display();
        }


        private static void Test1()
        {
            MenuItem mi1 = new MenuItem("mi1", "MenuItem1");
            MenuItem mi2 = new MenuItem("mi2", "MenuItem2");
            MenuItem mi3 = new MenuItem("mi3", "MenuItem3");
            MenuItem mi4 = new MenuItem("mi4", "MenuItem4");
            MenuItem mi5 = new MenuItem("mi5", "MenuItem5");

            mi1.Select += new EventHandler(mi1_Select);
            mi2.Select += new EventHandler(mi2_Select);
            mi3.Select += new EventHandler(mi3_Select);
            mi4.Select += new EventHandler(mi4_Select);
            mi5.Select += new EventHandler(mi5_Select);

            menu.Items.Add(mi1);
            menu.Items.Add(mi2);
            menu.Items.Add(mi3);
            menu.Items.Add(mi4);
            menu.Items.Add(mi5);

            MenuHotKeyedItem mhki1 = new MenuHotKeyedItem(
                "mhki1", "MenuHotKeyed_fuc...ngItem1", 'f');

            if (!menu.HotKeyAvailable(mhki1.HotKey))
            {
                Console.WriteLine("Not available, but still");
            }

            mhki1.Select += new EventHandler(mhki1_Select);
            menu.Items.Add(mhki1);

            MenuItem mi6 = new MenuItem("mi6", "MenuItem6");
            mi6.Select += new EventHandler(mi6_Select);
            menu.Items.Add(mi6);

            menu.Run();
        }

        static void mhki1_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi6_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi1_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi2_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi3_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi4_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

        static void mi5_Select(object sender, EventArgs e)
        {
            Console.WriteLine("{0} selected", (sender as MenuItem).Name);
        }

    }
}
